{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# E-Commerce Recommendations"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<b> Author:</b> Dominick DiTucci <br>\n",
    "<b>email:</b> djditucci@gmail.com<br>\n",
    "<br>\n",
    "The premise of this project is a hypothetical company, \"The Company\", in the e-commerce industry that would like to develop a recommendation system. \"The Company\" specializes in selling adhesives and sealants in addition to many related products in other categories. Our purpose is to identify reasonable complements to items a customer is interested in by identifying other items that are often purchased in the same transaction as the item of interest. The reasonable complements can be recommended to the customer through the context of \"customers who viewed ... also viewed...\" and \"customers who purchased ... also purchased...\" for the purpose of identifying alternative items or add-on items.\n",
    "\n",
    "The recommendations will be generated by using the apriori algorithm to extract frequent itemsets for association rule mining. The association rules will take the antecedent (item being viewed/purchased) and recommend associated consequents (complementary items) with the specified support and lift.\n",
    "\n",
    "####  <u> Key Terms </u>\n",
    "<ul><b>Association Rules:</b> Probability of association between items based on how frequently they are purchased together. If (X) purchased then (Y) has a higher probability of being purchased. </ul>\n",
    "<ul><b>Antecedent:</b> Item being viewed or purchased. </ul> \n",
    "<ul><b>Consequent:</b> Other item(s) that are frequently purchased in the same transaction.</ul>\n",
    "<ul><b>Support:</b> The relative frequency the antecedent and consequent show up in the same transactions.</ul>\n",
    "<ul><b>Lift:</b> The ratio of the observed support to what is expected if the two rules were independent and the item association was completely random.</ul>\n",
    "<ul><b>Confidence:</b> The reliability measure for the association rules.</ul>\n",
    "<br>\n",
    "The data used will be two datasets that have been combined. There is a dataset with six months of transactions where items in the \"adhesives and sealants\" category were purchased and another dataset containing all transactions over a two week period. The raw data contains:\n",
    "\n",
    "<ul><b>Order Number:</b> The unique identifier for each individual transaction</ul>\n",
    "<ul><b>l1:</b> Level 1 product identifier (most broad)</ul>\n",
    "<ul><b>l2:</b> Level 2 product identifier</ul>\n",
    "<ul><b>l3:</b> Level 3 product identifier (most granular)</ul>\n",
    "<ul><b>Sku:</b> The unique identifier for a specific item</ul>\n",
    "<ul><b>Brand:</b> The unique identifier for the specific brand of an item </ul>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Import Libraries\n",
    "import sqlite3\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "#!pip install mlxtend\n",
    "from mlxtend.frequent_patterns import apriori\n",
    "from mlxtend.frequent_patterns import association_rules\n",
    "from mlxtend.preprocessing import TransactionEncoder"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Data Preparation\n",
    "Load the raw data into pandas dataframes and seperate into columns."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Load txt files into pandas and separate columns \n",
    "adhesiveSealantTrans = pd.read_csv(\"/Users/DJ/E-Commerce-Recommendations/e-comm-data/Transactions with A&S.txt\",sep='\\t', header=0)\n",
    "allTransaction = pd.read_csv(\"/Users/DJ/E-Commerce-Recommendations/e-comm-data/All Transations - 2 Weeks.txt\", sep='\\t', header=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>order_number</th>\n",
       "      <th>l1</th>\n",
       "      <th>l2</th>\n",
       "      <th>l3</th>\n",
       "      <th>sku</th>\n",
       "      <th>brand</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1182478</td>\n",
       "      <td>Adhesives, Sealants and Tape</td>\n",
       "      <td>Putties</td>\n",
       "      <td>Putties</td>\n",
       "      <td>122821</td>\n",
       "      <td>2180</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>63908</td>\n",
       "      <td>Adhesives, Sealants and Tape</td>\n",
       "      <td>Caulks</td>\n",
       "      <td>Caulks and Sealants</td>\n",
       "      <td>276172</td>\n",
       "      <td>1054</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1165840</td>\n",
       "      <td>Adhesives, Sealants and Tape</td>\n",
       "      <td>Concrete and Asphalt</td>\n",
       "      <td>Concrete Cleaners and Sealers</td>\n",
       "      <td>110119</td>\n",
       "      <td>4326</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>928748</td>\n",
       "      <td>Material Handling</td>\n",
       "      <td>Casters and Wheels</td>\n",
       "      <td>Plate Casters</td>\n",
       "      <td>71052</td>\n",
       "      <td>1793</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1088891</td>\n",
       "      <td>Adhesives, Sealants and Tape</td>\n",
       "      <td>Glues and Cements</td>\n",
       "      <td>Retaining Compounds</td>\n",
       "      <td>251285</td>\n",
       "      <td>2515</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   order_number                            l1                    l2  \\\n",
       "0       1182478  Adhesives, Sealants and Tape               Putties   \n",
       "1         63908  Adhesives, Sealants and Tape                Caulks   \n",
       "2       1165840  Adhesives, Sealants and Tape  Concrete and Asphalt   \n",
       "3        928748             Material Handling    Casters and Wheels   \n",
       "4       1088891  Adhesives, Sealants and Tape     Glues and Cements   \n",
       "\n",
       "                              l3     sku  brand  \n",
       "0                        Putties  122821   2180  \n",
       "1            Caulks and Sealants  276172   1054  \n",
       "2  Concrete Cleaners and Sealers  110119   4326  \n",
       "3                  Plate Casters   71052   1793  \n",
       "4            Retaining Compounds  251285   2515  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Verify the data loaded correctly\n",
    "adhesiveSealantTrans.head(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>order_number</th>\n",
       "      <th>l1</th>\n",
       "      <th>l2</th>\n",
       "      <th>l3</th>\n",
       "      <th>sku</th>\n",
       "      <th>brand</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>168266</td>\n",
       "      <td>Power Tools</td>\n",
       "      <td>Power Saws and Accessories</td>\n",
       "      <td>Reciprocating Saw Blades</td>\n",
       "      <td>265105</td>\n",
       "      <td>2768</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>123986</td>\n",
       "      <td>Safety</td>\n",
       "      <td>Spill Control Supplies</td>\n",
       "      <td>Temporary Leak Repair</td>\n",
       "      <td>215839</td>\n",
       "      <td>586</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>158978</td>\n",
       "      <td>Hardware</td>\n",
       "      <td>Door Hardware</td>\n",
       "      <td>Thresholds</td>\n",
       "      <td>284756</td>\n",
       "      <td>1793</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>449035</td>\n",
       "      <td>Electronics, Appliances, and Batteries</td>\n",
       "      <td>Batteries</td>\n",
       "      <td>Standard Batteries</td>\n",
       "      <td>12579</td>\n",
       "      <td>1231</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>781232</td>\n",
       "      <td>Motors</td>\n",
       "      <td>General Purpose AC Motors</td>\n",
       "      <td>General Purpose AC Motors</td>\n",
       "      <td>194681</td>\n",
       "      <td>2603</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   order_number                                      l1  \\\n",
       "0        168266                             Power Tools   \n",
       "1        123986                                  Safety   \n",
       "2        158978                                Hardware   \n",
       "3        449035  Electronics, Appliances, and Batteries   \n",
       "4        781232                                  Motors   \n",
       "\n",
       "                           l2                         l3     sku  brand  \n",
       "0  Power Saws and Accessories   Reciprocating Saw Blades  265105   2768  \n",
       "1      Spill Control Supplies      Temporary Leak Repair  215839    586  \n",
       "2               Door Hardware                 Thresholds  284756   1793  \n",
       "3                   Batteries         Standard Batteries   12579   1231  \n",
       "4   General Purpose AC Motors  General Purpose AC Motors  194681   2603  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Verify the data loaded correctly\n",
    "allTransaction.head(5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<br>\n",
    "Both dataframes will be combined since the goal is recommending the items most frequently associated with each other regardless of category."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>order_number</th>\n",
       "      <th>l1</th>\n",
       "      <th>l2</th>\n",
       "      <th>l3</th>\n",
       "      <th>sku</th>\n",
       "      <th>brand</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1182478</td>\n",
       "      <td>Adhesives, Sealants and Tape</td>\n",
       "      <td>Putties</td>\n",
       "      <td>Putties</td>\n",
       "      <td>122821</td>\n",
       "      <td>2180</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>63908</td>\n",
       "      <td>Adhesives, Sealants and Tape</td>\n",
       "      <td>Caulks</td>\n",
       "      <td>Caulks and Sealants</td>\n",
       "      <td>276172</td>\n",
       "      <td>1054</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1165840</td>\n",
       "      <td>Adhesives, Sealants and Tape</td>\n",
       "      <td>Concrete and Asphalt</td>\n",
       "      <td>Concrete Cleaners and Sealers</td>\n",
       "      <td>110119</td>\n",
       "      <td>4326</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>928748</td>\n",
       "      <td>Material Handling</td>\n",
       "      <td>Casters and Wheels</td>\n",
       "      <td>Plate Casters</td>\n",
       "      <td>71052</td>\n",
       "      <td>1793</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1088891</td>\n",
       "      <td>Adhesives, Sealants and Tape</td>\n",
       "      <td>Glues and Cements</td>\n",
       "      <td>Retaining Compounds</td>\n",
       "      <td>251285</td>\n",
       "      <td>2515</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   order_number                            l1                    l2  \\\n",
       "0       1182478  Adhesives, Sealants and Tape               Putties   \n",
       "1         63908  Adhesives, Sealants and Tape                Caulks   \n",
       "2       1165840  Adhesives, Sealants and Tape  Concrete and Asphalt   \n",
       "3        928748             Material Handling    Casters and Wheels   \n",
       "4       1088891  Adhesives, Sealants and Tape     Glues and Cements   \n",
       "\n",
       "                              l3     sku  brand  \n",
       "0                        Putties  122821   2180  \n",
       "1            Caulks and Sealants  276172   1054  \n",
       "2  Concrete Cleaners and Sealers  110119   4326  \n",
       "3                  Plate Casters   71052   1793  \n",
       "4            Retaining Compounds  251285   2515  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Combine transaction data since adhesives/sealants do not need to be seperate from all other transactions\n",
    "frames = [adhesiveSealantTrans, allTransaction]\n",
    "allTransactions = pd.concat(frames)\n",
    "\n",
    "# Check data loaded correctly\n",
    "allTransactions.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(5494816, 6)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# See final shape of combined dataset\n",
    "allTransactions.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "All Transactions Data order_number     int64\n",
      "l1              object\n",
      "l2              object\n",
      "l3              object\n",
      "sku              int64\n",
      "brand            int64\n",
      "dtype: object\n"
     ]
    }
   ],
   "source": [
    "# Check data types\n",
    "print(\"All Transactions Data\", allTransactions.dtypes)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exploratory  Analysis"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### SQL Queries"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Brief analysis will be done using SQL queries. First, the database will be created. Then the database will be connected and loaded with the combined data."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Create database\n",
    "db = sqlite3.connect(\"transactions.db\")\n",
    "\n",
    "# Connect to database\n",
    "con = sqlite3.connect(\"/Users/DJ/E-Commerce-Recommendations/transactions.db\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Move dataframe to sql table in transactions.db\n",
    "allTransactions.to_sql(\"all_trans\", con, if_exists=\"replace\", index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Unique Order Numbers: \n",
      "    COUNT(DISTINCT order_number)\n",
      "0                       1243048\n",
      "\n",
      "Unique Brands: \n",
      "    COUNT(DISTINCT Brand)\n",
      "0                   4841\n",
      "\n",
      "Unique Sku: \n",
      "    COUNT(DISTINCT Sku)\n",
      "0               333127\n",
      "\n",
      "Unique l1: \n",
      "    COUNT(DISTINCT l1)\n",
      "0                  33\n",
      "\n",
      "Unique l2: \n",
      "    COUNT(DISTINCT l2)\n",
      "0                 593\n",
      "\n",
      "Unique l3: \n",
      "    COUNT(DISTINCT l3)\n",
      "0                6355\n"
     ]
    }
   ],
   "source": [
    "# See unique values for all features\n",
    "print(\"Unique Order Numbers: \\n\", pd.read_sql_query(\"SELECT COUNT(DISTINCT order_number) FROM all_Trans;\", con))\n",
    "print(\"\\nUnique Brands: \\n\", pd.read_sql_query(\"SELECT COUNT(DISTINCT Brand) FROM all_Trans;\", con))\n",
    "print(\"\\nUnique Sku: \\n\", pd.read_sql_query(\"SELECT COUNT(DISTINCT Sku) FROM all_Trans;\", con))\n",
    "print(\"\\nUnique l1: \\n\", pd.read_sql_query(\"SELECT COUNT(DISTINCT l1) FROM all_Trans;\", con))\n",
    "print(\"\\nUnique l2: \\n\", pd.read_sql_query(\"SELECT COUNT(DISTINCT l2) FROM all_Trans;\", con))\n",
    "print(\"\\nUnique l3: \\n\", pd.read_sql_query(\"SELECT COUNT(DISTINCT l3) FROM all_Trans;\", con))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's verify there are no missing values."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "All Transactions Missing Data\n",
      "Brand    ProportionMissing\n",
      "0                0.0\n",
      "Sku    ProportionMissing\n",
      "0                0.0\n",
      "L1    ProportionMissing\n",
      "0                0.0\n",
      "L2    ProportionMissing\n",
      "0                0.0\n",
      "L3    ProportionMissing\n",
      "0                0.0\n"
     ]
    }
   ],
   "source": [
    "# Check all_trans for missing data\n",
    "print(\"\\nAll Transactions Missing Data\")\n",
    "print(\"Brand\", pd.read_sql_query(\"SELECT CAST(SUM(CASE WHEN brand is NULL THEN 1 ELSE 0 END) as float)/COUNT(*) as ProportionMissing FROM all_trans;\", con))\n",
    "print(\"Sku\", pd.read_sql_query(\"SELECT CAST(SUM(CASE WHEN sku is NULL THEN 1 ELSE 0 END) as float)/COUNT(*) as ProportionMissing FROM all_trans;\", con))\n",
    "print(\"L1\", pd.read_sql_query(\"SELECT CAST(SUM(CASE WHEN l1 is NULL THEN 1 ELSE 0 END) as float)/COUNT(*) as ProportionMissing FROM all_trans;\", con))\n",
    "print(\"L2\", pd.read_sql_query(\"SELECT CAST(SUM(CASE WHEN l2 is NULL THEN 1 ELSE 0 END) as float)/COUNT(*) as ProportionMissing FROM all_trans;\", con))\n",
    "print(\"L3\", pd.read_sql_query(\"SELECT CAST(SUM(CASE WHEN l3 is NULL THEN 1 ELSE 0 END) as float)/COUNT(*) as ProportionMissing FROM all_trans;\", con))\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "There is no missing data.\n",
    "\n",
    "What are the 10 most-purchased items?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>l1</th>\n",
       "      <th>l2</th>\n",
       "      <th>l3</th>\n",
       "      <th>COUNT(sku)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Adhesives, Sealants and Tape</td>\n",
       "      <td>Tapes</td>\n",
       "      <td>Electrical Tapes</td>\n",
       "      <td>35812</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Electronics, Appliances, and Batteries</td>\n",
       "      <td>Batteries</td>\n",
       "      <td>Standard Batteries</td>\n",
       "      <td>30079</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Electronics, Appliances, and Batteries</td>\n",
       "      <td>Batteries</td>\n",
       "      <td>Standard Batteries</td>\n",
       "      <td>25550</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Electronics, Appliances, and Batteries</td>\n",
       "      <td>Batteries</td>\n",
       "      <td>Standard Batteries</td>\n",
       "      <td>10981</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Adhesives, Sealants and Tape</td>\n",
       "      <td>Thread and Gasket Sealants</td>\n",
       "      <td>Pipe Sealant Tape</td>\n",
       "      <td>10920</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>Adhesives, Sealants and Tape</td>\n",
       "      <td>Tapes</td>\n",
       "      <td>Duct and Cloth Tapes</td>\n",
       "      <td>10162</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>Adhesives, Sealants and Tape</td>\n",
       "      <td>Tapes</td>\n",
       "      <td>Duct and Cloth Tapes</td>\n",
       "      <td>8549</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>Electronics, Appliances, and Batteries</td>\n",
       "      <td>Batteries</td>\n",
       "      <td>Standard Batteries</td>\n",
       "      <td>8468</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>Cleaning</td>\n",
       "      <td>Paper Products and Dispensers</td>\n",
       "      <td>Paper Towels, Rolls</td>\n",
       "      <td>8288</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>Adhesives, Sealants and Tape</td>\n",
       "      <td>Thread and Gasket Sealants</td>\n",
       "      <td>Pipe Sealant Tape</td>\n",
       "      <td>8229</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                       l1                             l2  \\\n",
       "0            Adhesives, Sealants and Tape                          Tapes   \n",
       "1  Electronics, Appliances, and Batteries                      Batteries   \n",
       "2  Electronics, Appliances, and Batteries                      Batteries   \n",
       "3  Electronics, Appliances, and Batteries                      Batteries   \n",
       "4            Adhesives, Sealants and Tape     Thread and Gasket Sealants   \n",
       "5            Adhesives, Sealants and Tape                          Tapes   \n",
       "6            Adhesives, Sealants and Tape                          Tapes   \n",
       "7  Electronics, Appliances, and Batteries                      Batteries   \n",
       "8                                Cleaning  Paper Products and Dispensers   \n",
       "9            Adhesives, Sealants and Tape     Thread and Gasket Sealants   \n",
       "\n",
       "                     l3  COUNT(sku)  \n",
       "0      Electrical Tapes       35812  \n",
       "1    Standard Batteries       30079  \n",
       "2    Standard Batteries       25550  \n",
       "3    Standard Batteries       10981  \n",
       "4     Pipe Sealant Tape       10920  \n",
       "5  Duct and Cloth Tapes       10162  \n",
       "6  Duct and Cloth Tapes        8549  \n",
       "7    Standard Batteries        8468  \n",
       "8   Paper Towels, Rolls        8288  \n",
       "9     Pipe Sealant Tape        8229  "
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# See top 10 items in ALL transactons\n",
    "pd.read_sql_query(\"SELECT l1,l2, l3, COUNT(sku) FROM all_trans GROUP BY sku ORDER BY COUNT(sku) DESC LIMIT 10;\", con)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Electrical tape is the most-purchased item with almost 36,000 units in the transaction data. Batteries are the next most-purchased items, followed by pipe sealant tape.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Building a recommendation system\n",
    "\n",
    "Given the limited amount of data available (unique identifiers and categories only), we will find frequent itemsets using the apriori algorithm to find which items are purchased together more often than expected. All items will be grouped by their order number to identify what was purchased in the same transaction. We will then use the most-granular (l3) product hierarchy to find what each item is and make recommendations based on that. The broader product hierarchy levels will be dropped along with the numerical unique identifiers (brand and sku) as they are not useful for our purposes. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Prepare Data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We know the shape of the dataframe is (5494816, 6) before altering it.\n",
    "\n",
    "Sku and brand will be dropped since we do not have information on which items and brands these numbers correspond to. The l1 and l2 categories will also be dropped because we need the most granular (l3) data available to make meaningful recommendations."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Drop sku and brand \n",
    "allTransactions.drop('sku', axis=1, inplace=True)\n",
    "allTransactions.drop('brand', axis=1, inplace=True)\n",
    "\n",
    "# Drop most broad categories and keep most granular\n",
    "allTransactions.drop('l1', axis=1, inplace=True)\n",
    "allTransactions.drop('l2', axis=1, inplace=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now the data will be grouped by order number so all items purchased in the same transaction are in a list together. The length of the list should match the count of unique order numbers (1243048)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "order_number\n",
       "1                     [Steel-Toe Work Boots and Shoes]\n",
       "2    [Bib Overalls, Traffic Safety Vests, Work Cove...\n",
       "3                                          [Rainsuits]\n",
       "4                     [Steel-Toe Work Boots and Shoes]\n",
       "5                     [Steel-Toe Work Boots and Shoes]\n",
       "Name: l3, dtype: object"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Combine items into lists by order number\n",
    "grouped = allTransactions.groupby('order_number')['l3'].apply(list)\n",
    "grouped.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1243048,)"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Check shape of list \n",
    "grouped.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "There are over 1 million orders. We will filter out orders with less than 10 items to make our data more relevant for finding items that are purchased together."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[['Bib Overalls',\n",
       "  'Traffic Safety Vests',\n",
       "  'Work Coveralls',\n",
       "  'Bib Overalls',\n",
       "  'Traffic Safety Vests',\n",
       "  'Traffic Safety Vests',\n",
       "  'Bib Overalls',\n",
       "  'Headbands, Sweatbands and Cooling Headwear',\n",
       "  'Hard Hats',\n",
       "  'Hard Hat Accessories',\n",
       "  'Traffic Warning Flags and Banners',\n",
       "  'Traffic Warning Flags and Banners',\n",
       "  'Bib Overalls',\n",
       "  'Hard Hats',\n",
       "  'High Visibility Shirts and Sweatshirts'],\n",
       " ['Cut-Resistant Gloves',\n",
       "  'Cut-Resistant Gloves',\n",
       "  'Leather Work Gloves',\n",
       "  'Sports Drinks and Thirst Quenchers',\n",
       "  'Safety Glasses',\n",
       "  'Leather Work Gloves',\n",
       "  'Leather Work Gloves',\n",
       "  'Leather Work Gloves',\n",
       "  'Leather Work Gloves',\n",
       "  'Leather Work Gloves',\n",
       "  'Leather Work Gloves',\n",
       "  'Leather Work Gloves',\n",
       "  'Leather Work Gloves',\n",
       "  'Leather Work Gloves',\n",
       "  'Leather Work Gloves',\n",
       "  'Standard Batteries',\n",
       "  'Standard Batteries',\n",
       "  'Standard Batteries',\n",
       "  'Standard Batteries',\n",
       "  'Standard Batteries',\n",
       "  'Standard Batteries',\n",
       "  'Safety Glasses',\n",
       "  'Safety Glasses',\n",
       "  'Safety Glasses',\n",
       "  'Cut-Resistant Gloves',\n",
       "  'Cut-Resistant Gloves',\n",
       "  'Leather Work Gloves',\n",
       "  'Leather Work Gloves',\n",
       "  'Leather Work Gloves',\n",
       "  'Leather Work Gloves',\n",
       "  'Leather Work Gloves',\n",
       "  'Leather Work Gloves',\n",
       "  'Ponchos',\n",
       "  'Ear Plugs',\n",
       "  'Headbands, Sweatbands and Cooling Headwear',\n",
       "  'Headbands, Sweatbands and Cooling Headwear',\n",
       "  'Headbands, Sweatbands and Cooling Headwear',\n",
       "  'Headbands, Sweatbands and Cooling Headwear',\n",
       "  'Headbands, Sweatbands and Cooling Headwear',\n",
       "  'Duct and Cloth Tapes',\n",
       "  'Duct and Cloth Tapes',\n",
       "  'Duct and Cloth Tapes',\n",
       "  'Cut-Resistant Sleeves',\n",
       "  'Ear Plugs',\n",
       "  'Ear Plugs',\n",
       "  'Ear Plugs',\n",
       "  'Ear Plugs',\n",
       "  'Ear Plugs',\n",
       "  'Cut-Resistant Gloves',\n",
       "  'Cut-Resistant Gloves',\n",
       "  'Cut-Resistant Gloves',\n",
       "  'Standard Batteries',\n",
       "  'Standard Batteries',\n",
       "  'Standard Batteries',\n",
       "  'Standard Batteries',\n",
       "  'Standard Batteries',\n",
       "  'Standard Batteries',\n",
       "  'Standard Batteries',\n",
       "  'Welding Gloves',\n",
       "  'Electrical Tapes',\n",
       "  'Cut-Resistant Gloves',\n",
       "  'Cut-Resistant Gloves',\n",
       "  'Cut-Resistant Gloves',\n",
       "  'Cut-Resistant Gloves',\n",
       "  'Cut-Resistant Gloves',\n",
       "  'Glove Holder Clips',\n",
       "  'Glove Holder Clips',\n",
       "  'Glove Holder Clips',\n",
       "  'Leather Work Gloves',\n",
       "  'Leather Work Gloves',\n",
       "  'Leather Work Gloves',\n",
       "  'Cut-Resistant Gloves',\n",
       "  'Leather Work Gloves',\n",
       "  'Headbands, Sweatbands and Cooling Headwear',\n",
       "  'Headbands, Sweatbands and Cooling Headwear',\n",
       "  'Cut-Resistant Gloves',\n",
       "  'Ponchos',\n",
       "  'Ponchos',\n",
       "  'Ponchos',\n",
       "  'Safety Glasses',\n",
       "  'Safety Glasses',\n",
       "  'Safety Glasses',\n",
       "  'Safety Glasses',\n",
       "  'Cut-Resistant Gloves',\n",
       "  'Cut-Resistant Gloves',\n",
       "  'Ear Plugs',\n",
       "  'Ear Plugs',\n",
       "  'Ear Plugs',\n",
       "  'Ponchos',\n",
       "  'Chemical Resistant Gloves',\n",
       "  'Cartridges And Filters',\n",
       "  'Chemical Resistant Gloves',\n",
       "  'Ponchos',\n",
       "  'Cut-Resistant Gloves',\n",
       "  'Cut-Resistant Gloves',\n",
       "  'Safety Glasses',\n",
       "  'Safety Glasses',\n",
       "  'Sports Drinks and Thirst Quenchers'],\n",
       " ['Paper Cutter Dispensers',\n",
       "  'Surge Protected Outlet Strips',\n",
       "  'Shop Vacuum Cleaners',\n",
       "  'Plain-Toe PVC and Rubber Boots',\n",
       "  'Cleaning Rags',\n",
       "  'Food Service Cutting Boards',\n",
       "  'Extension Cords',\n",
       "  'Plain-Toe PVC and Rubber Boots',\n",
       "  'Push Brooms',\n",
       "  'Ice Melting Compounds',\n",
       "  'Disposable Gloves',\n",
       "  'Surface Protection Films',\n",
       "  'Portable Blowers and Carpet Dryers',\n",
       "  'Absorbent Socks and Booms',\n",
       "  'Dollies',\n",
       "  'Absorbent Rolls',\n",
       "  'Utility Knives',\n",
       "  'Plain-Toe PVC and Rubber Boots',\n",
       "  'Tarps',\n",
       "  'Attached Lid Containers',\n",
       "  'Storage Pails and Buckets',\n",
       "  'Disposable Respirators',\n",
       "  'Duct and Cloth Tapes',\n",
       "  'Air Circulators',\n",
       "  'Disposable Gloves',\n",
       "  'Squeegees',\n",
       "  'Hard Hats',\n",
       "  'Packing Paper',\n",
       "  'Disposable Gloves',\n",
       "  'Handheld Flashlights',\n",
       "  'Plain-Toe PVC and Rubber Boots',\n",
       "  'Squeegees',\n",
       "  'Masonry Miscellaneous Tool Accessories',\n",
       "  'Gym Equipment Wipes',\n",
       "  'Paper Towels, Rolls',\n",
       "  'Markers',\n",
       "  'Extension Cords']]"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Filter out small orders\n",
    "filtered_group = [x for x in grouped if len(x)>=10 ]\n",
    "\n",
    "# Sample first few large orders\n",
    "filtered_group[:3]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now the data can be one-hot encoded using the MLxtend library."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>12 Volt Accessories</th>\n",
       "      <th>12-Point Flange Head Cap Screws</th>\n",
       "      <th>3-Ring Binder Accessories</th>\n",
       "      <th>3-Ring Binders</th>\n",
       "      <th>3.3 Inch Diameter Motors</th>\n",
       "      <th>3D Printing Materials</th>\n",
       "      <th>4-Way and Box Parallels</th>\n",
       "      <th>4.4 Inch Diameter Motors</th>\n",
       "      <th>5 X 20mm Glass and Ceramic Fuses</th>\n",
       "      <th>50 Hz Motors</th>\n",
       "      <th>...</th>\n",
       "      <th>Wrist Watches</th>\n",
       "      <th>Writing Instrument Accessories</th>\n",
       "      <th>Y Strainers</th>\n",
       "      <th>Yard Hydrants</th>\n",
       "      <th>Yoke Ends</th>\n",
       "      <th>Zone Valve Accessories</th>\n",
       "      <th>Zone Valve Actuators</th>\n",
       "      <th>Zone Valves</th>\n",
       "      <th>Zoning Dampers</th>\n",
       "      <th>pH Meters</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>...</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>...</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>...</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>...</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>...</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 5603 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   12 Volt Accessories  12-Point Flange Head Cap Screws  \\\n",
       "0                False                            False   \n",
       "1                False                            False   \n",
       "2                False                            False   \n",
       "3                False                            False   \n",
       "4                False                            False   \n",
       "\n",
       "   3-Ring Binder Accessories  3-Ring Binders  3.3 Inch Diameter Motors  \\\n",
       "0                      False           False                     False   \n",
       "1                      False           False                     False   \n",
       "2                      False           False                     False   \n",
       "3                      False           False                     False   \n",
       "4                      False           False                     False   \n",
       "\n",
       "   3D Printing Materials  4-Way and Box Parallels  4.4 Inch Diameter Motors  \\\n",
       "0                  False                    False                     False   \n",
       "1                  False                    False                     False   \n",
       "2                  False                    False                     False   \n",
       "3                  False                    False                     False   \n",
       "4                  False                    False                     False   \n",
       "\n",
       "   5 X 20mm Glass and Ceramic Fuses  50 Hz Motors    ...      Wrist Watches  \\\n",
       "0                             False         False    ...              False   \n",
       "1                             False         False    ...              False   \n",
       "2                             False         False    ...              False   \n",
       "3                             False         False    ...              False   \n",
       "4                             False         False    ...              False   \n",
       "\n",
       "   Writing Instrument Accessories  Y Strainers  Yard Hydrants  Yoke Ends  \\\n",
       "0                           False        False          False      False   \n",
       "1                           False        False          False      False   \n",
       "2                           False        False          False      False   \n",
       "3                           False        False          False      False   \n",
       "4                           False        False          False      False   \n",
       "\n",
       "   Zone Valve Accessories  Zone Valve Actuators  Zone Valves  Zoning Dampers  \\\n",
       "0                   False                 False        False           False   \n",
       "1                   False                 False        False           False   \n",
       "2                   False                 False        False           False   \n",
       "3                   False                 False        False           False   \n",
       "4                   False                 False        False           False   \n",
       "\n",
       "   pH Meters  \n",
       "0      False  \n",
       "1      False  \n",
       "2      False  \n",
       "3      False  \n",
       "4      False  \n",
       "\n",
       "[5 rows x 5603 columns]"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# One-hot encode data in pandas dataframe\n",
    "te = TransactionEncoder()\n",
    "te_ary = te.fit(filtered_group).transform(filtered_group)\n",
    "transaction_group = pd.DataFrame(te_ary, columns=te.columns_)\n",
    "transaction_group.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Find itemsets that are in at least 1% of our data:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>support</th>\n",
       "      <th>itemsets</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.055478</td>\n",
       "      <td>(Abrasive Cut-Off and Chop Wheels)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.020519</td>\n",
       "      <td>(Abrasive Rolls)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.030859</td>\n",
       "      <td>(Absorbent Pads)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.014272</td>\n",
       "      <td>(Adhesive Bandages)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.019328</td>\n",
       "      <td>(Adhesives)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.024291</td>\n",
       "      <td>(Adjustable Wrenches)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>0.010042</td>\n",
       "      <td>(Aerosol Dusters)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>0.021390</td>\n",
       "      <td>(Air Guns)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>0.013432</td>\n",
       "      <td>(American Glass and Ceramic Fuses)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>0.043100</td>\n",
       "      <td>(Anti-Seize Compounds)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>0.013135</td>\n",
       "      <td>(Anti-Slip Tapes)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>0.012967</td>\n",
       "      <td>(Antimicrobial and Antibacterial Soap)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>0.039541</td>\n",
       "      <td>(Automotive Cleaners and Degreasers)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>0.043902</td>\n",
       "      <td>(Ball Valves)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>0.019671</td>\n",
       "      <td>(Barbed Hose Fittings)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>0.044482</td>\n",
       "      <td>(Barrier, Flagging and Underground Tapes)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>0.014463</td>\n",
       "      <td>(Bit Holders)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>0.047575</td>\n",
       "      <td>(Black Pipe)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>0.057670</td>\n",
       "      <td>(Black Pipe Fittings)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>0.030057</td>\n",
       "      <td>(Body and Hand Wipes)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>0.016441</td>\n",
       "      <td>(Box, I-Beam, and Torpedo Levels)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>0.010958</td>\n",
       "      <td>(Brass Pipe)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>0.022802</td>\n",
       "      <td>(Brass Pipe Fittings)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>0.010783</td>\n",
       "      <td>(Bungee Cords and Tiedowns)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>0.019893</td>\n",
       "      <td>(Butt Splice Connectors)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>0.137088</td>\n",
       "      <td>(Cable Ties)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>0.020374</td>\n",
       "      <td>(Canvas, Chore and Jersey Gloves)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>0.022734</td>\n",
       "      <td>(Cartridges And Filters)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>0.026246</td>\n",
       "      <td>(Caulk Guns)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>0.071744</td>\n",
       "      <td>(Caulks and Sealants)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1130</th>\n",
       "      <td>0.010676</td>\n",
       "      <td>(Flat Washers, Cable Ties, Hex Nuts, Lock Wash...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1131</th>\n",
       "      <td>0.011241</td>\n",
       "      <td>(Safety Glasses, Cut-Resistant Gloves, Leather...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1132</th>\n",
       "      <td>0.013409</td>\n",
       "      <td>(Safety Glasses, Cut-Resistant Gloves, Coated ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1133</th>\n",
       "      <td>0.011248</td>\n",
       "      <td>(Safety Glasses, Coated Gloves, Disposable Glo...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1134</th>\n",
       "      <td>0.012325</td>\n",
       "      <td>(Safety Glasses, Leather Work Gloves, Coated G...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1135</th>\n",
       "      <td>0.013348</td>\n",
       "      <td>(Safety Glasses, Cut-Resistant Gloves, Disposa...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1136</th>\n",
       "      <td>0.010951</td>\n",
       "      <td>(Safety Glasses, Cut-Resistant Gloves, Duct an...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1137</th>\n",
       "      <td>0.010385</td>\n",
       "      <td>(Safety Glasses, Cut-Resistant Gloves, Leather...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1138</th>\n",
       "      <td>0.013845</td>\n",
       "      <td>(Safety Glasses, Cut-Resistant Gloves, Electri...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1139</th>\n",
       "      <td>0.016258</td>\n",
       "      <td>(Safety Glasses, Cut-Resistant Gloves, Leather...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1140</th>\n",
       "      <td>0.010011</td>\n",
       "      <td>(Safety Glasses, Cut-Resistant Gloves, Reader ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1141</th>\n",
       "      <td>0.010042</td>\n",
       "      <td>(Safety Glasses, Disposable Gloves, Duct and C...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1142</th>\n",
       "      <td>0.010363</td>\n",
       "      <td>(Safety Glasses, Electrical Tapes, Standard Ba...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1143</th>\n",
       "      <td>0.010912</td>\n",
       "      <td>(Safety Glasses, Leather Work Gloves, Disposab...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1144</th>\n",
       "      <td>0.010004</td>\n",
       "      <td>(Trash Bags, Disposable Gloves, Toilet Paper, ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1145</th>\n",
       "      <td>0.011371</td>\n",
       "      <td>(Safety Glasses, Leather Work Gloves, Duct and...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1146</th>\n",
       "      <td>0.013035</td>\n",
       "      <td>(Hex Head Cap Screws, Flat Washers, Electrical...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1147</th>\n",
       "      <td>0.011241</td>\n",
       "      <td>(Hex Head Cap Screws, Electrical Tapes, Flat W...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1148</th>\n",
       "      <td>0.012295</td>\n",
       "      <td>(Safety Glasses, Leather Work Gloves, Electric...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1149</th>\n",
       "      <td>0.015013</td>\n",
       "      <td>(Jobber Length Drill Bits, Hex Head Cap Screws...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1150</th>\n",
       "      <td>0.016999</td>\n",
       "      <td>(Lock Nuts, Hex Head Cap Screws, Flat Washers,...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1151</th>\n",
       "      <td>0.026109</td>\n",
       "      <td>(Hex Head Cap Screws, Flat Washers, Hex Nuts, ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1152</th>\n",
       "      <td>0.010011</td>\n",
       "      <td>(Hex Head Cap Screws, Flat Washers, Hex Nuts, ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1153</th>\n",
       "      <td>0.011554</td>\n",
       "      <td>(Worm Gear Clamps, Hex Head Cap Screws, Flat W...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1154</th>\n",
       "      <td>0.012997</td>\n",
       "      <td>(Jobber Length Drill Bits, Hex Head Cap Screws...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1155</th>\n",
       "      <td>0.015899</td>\n",
       "      <td>(Lock Nuts, Hex Head Cap Screws, Flat Washers,...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1156</th>\n",
       "      <td>0.011248</td>\n",
       "      <td>(Jobber Length Drill Bits, Flat Washers, Hex N...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1157</th>\n",
       "      <td>0.013127</td>\n",
       "      <td>(Lock Nuts, Flat Washers, Hex Nuts, Lock Washers)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1158</th>\n",
       "      <td>0.012218</td>\n",
       "      <td>(Lock Nuts, Hex Head Cap Screws, Hex Nuts, Loc...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1159</th>\n",
       "      <td>0.011447</td>\n",
       "      <td>(Hex Nuts, Lock Washers, Hex Head Cap Screws, ...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1160 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       support                                           itemsets\n",
       "0     0.055478                 (Abrasive Cut-Off and Chop Wheels)\n",
       "1     0.020519                                   (Abrasive Rolls)\n",
       "2     0.030859                                   (Absorbent Pads)\n",
       "3     0.014272                                (Adhesive Bandages)\n",
       "4     0.019328                                        (Adhesives)\n",
       "5     0.024291                              (Adjustable Wrenches)\n",
       "6     0.010042                                  (Aerosol Dusters)\n",
       "7     0.021390                                         (Air Guns)\n",
       "8     0.013432                 (American Glass and Ceramic Fuses)\n",
       "9     0.043100                             (Anti-Seize Compounds)\n",
       "10    0.013135                                  (Anti-Slip Tapes)\n",
       "11    0.012967             (Antimicrobial and Antibacterial Soap)\n",
       "12    0.039541               (Automotive Cleaners and Degreasers)\n",
       "13    0.043902                                      (Ball Valves)\n",
       "14    0.019671                             (Barbed Hose Fittings)\n",
       "15    0.044482          (Barrier, Flagging and Underground Tapes)\n",
       "16    0.014463                                      (Bit Holders)\n",
       "17    0.047575                                       (Black Pipe)\n",
       "18    0.057670                              (Black Pipe Fittings)\n",
       "19    0.030057                              (Body and Hand Wipes)\n",
       "20    0.016441                  (Box, I-Beam, and Torpedo Levels)\n",
       "21    0.010958                                       (Brass Pipe)\n",
       "22    0.022802                              (Brass Pipe Fittings)\n",
       "23    0.010783                        (Bungee Cords and Tiedowns)\n",
       "24    0.019893                           (Butt Splice Connectors)\n",
       "25    0.137088                                       (Cable Ties)\n",
       "26    0.020374                  (Canvas, Chore and Jersey Gloves)\n",
       "27    0.022734                           (Cartridges And Filters)\n",
       "28    0.026246                                       (Caulk Guns)\n",
       "29    0.071744                              (Caulks and Sealants)\n",
       "...        ...                                                ...\n",
       "1130  0.010676  (Flat Washers, Cable Ties, Hex Nuts, Lock Wash...\n",
       "1131  0.011241  (Safety Glasses, Cut-Resistant Gloves, Leather...\n",
       "1132  0.013409  (Safety Glasses, Cut-Resistant Gloves, Coated ...\n",
       "1133  0.011248  (Safety Glasses, Coated Gloves, Disposable Glo...\n",
       "1134  0.012325  (Safety Glasses, Leather Work Gloves, Coated G...\n",
       "1135  0.013348  (Safety Glasses, Cut-Resistant Gloves, Disposa...\n",
       "1136  0.010951  (Safety Glasses, Cut-Resistant Gloves, Duct an...\n",
       "1137  0.010385  (Safety Glasses, Cut-Resistant Gloves, Leather...\n",
       "1138  0.013845  (Safety Glasses, Cut-Resistant Gloves, Electri...\n",
       "1139  0.016258  (Safety Glasses, Cut-Resistant Gloves, Leather...\n",
       "1140  0.010011  (Safety Glasses, Cut-Resistant Gloves, Reader ...\n",
       "1141  0.010042  (Safety Glasses, Disposable Gloves, Duct and C...\n",
       "1142  0.010363  (Safety Glasses, Electrical Tapes, Standard Ba...\n",
       "1143  0.010912  (Safety Glasses, Leather Work Gloves, Disposab...\n",
       "1144  0.010004  (Trash Bags, Disposable Gloves, Toilet Paper, ...\n",
       "1145  0.011371  (Safety Glasses, Leather Work Gloves, Duct and...\n",
       "1146  0.013035  (Hex Head Cap Screws, Flat Washers, Electrical...\n",
       "1147  0.011241  (Hex Head Cap Screws, Electrical Tapes, Flat W...\n",
       "1148  0.012295  (Safety Glasses, Leather Work Gloves, Electric...\n",
       "1149  0.015013  (Jobber Length Drill Bits, Hex Head Cap Screws...\n",
       "1150  0.016999  (Lock Nuts, Hex Head Cap Screws, Flat Washers,...\n",
       "1151  0.026109  (Hex Head Cap Screws, Flat Washers, Hex Nuts, ...\n",
       "1152  0.010011  (Hex Head Cap Screws, Flat Washers, Hex Nuts, ...\n",
       "1153  0.011554  (Worm Gear Clamps, Hex Head Cap Screws, Flat W...\n",
       "1154  0.012997  (Jobber Length Drill Bits, Hex Head Cap Screws...\n",
       "1155  0.015899  (Lock Nuts, Hex Head Cap Screws, Flat Washers,...\n",
       "1156  0.011248  (Jobber Length Drill Bits, Flat Washers, Hex N...\n",
       "1157  0.013127  (Lock Nuts, Flat Washers, Hex Nuts, Lock Washers)\n",
       "1158  0.012218  (Lock Nuts, Hex Head Cap Screws, Hex Nuts, Loc...\n",
       "1159  0.011447  (Hex Nuts, Lock Washers, Hex Head Cap Screws, ...\n",
       "\n",
       "[1160 rows x 2 columns]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Find items with minimal support using apriori algorithm to show which have any possible relationship\n",
    "apriori(transaction_group, min_support=0.01, use_colnames=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To remove any orders with only 1 item purchased, we'll create a column with the number of items in each order and then filter out single-item transactions."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>support</th>\n",
       "      <th>itemsets</th>\n",
       "      <th>length</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.055478</td>\n",
       "      <td>(Abrasive Cut-Off and Chop Wheels)</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.020519</td>\n",
       "      <td>(Abrasive Rolls)</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.030859</td>\n",
       "      <td>(Absorbent Pads)</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.014272</td>\n",
       "      <td>(Adhesive Bandages)</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.019328</td>\n",
       "      <td>(Adhesives)</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    support                            itemsets  length\n",
       "0  0.055478  (Abrasive Cut-Off and Chop Wheels)       1\n",
       "1  0.020519                    (Abrasive Rolls)       1\n",
       "2  0.030859                    (Absorbent Pads)       1\n",
       "3  0.014272                 (Adhesive Bandages)       1\n",
       "4  0.019328                         (Adhesives)       1"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Find frequent item sets and and number of items in each order\n",
    "freq_itemsets = apriori(transaction_group, min_support=0.01, use_colnames=True)\n",
    "freq_itemsets['length'] = freq_itemsets['itemsets'].apply(lambda x : len(x))\n",
    "freq_itemsets.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>support</th>\n",
       "      <th>itemsets</th>\n",
       "      <th>length</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>302</th>\n",
       "      <td>0.034891</td>\n",
       "      <td>(Black Pipe Fittings, Black Pipe)</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>315</th>\n",
       "      <td>0.021764</td>\n",
       "      <td>(Flat Washers, Black Pipe Fittings)</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>330</th>\n",
       "      <td>0.029003</td>\n",
       "      <td>(Disposable Gloves, Cable Ties)</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>332</th>\n",
       "      <td>0.028087</td>\n",
       "      <td>(Duct and Cloth Tapes, Cable Ties)</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>334</th>\n",
       "      <td>0.053065</td>\n",
       "      <td>(Electrical Tapes, Cable Ties)</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>336</th>\n",
       "      <td>0.036494</td>\n",
       "      <td>(Flat Washers, Cable Ties)</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>338</th>\n",
       "      <td>0.030003</td>\n",
       "      <td>(Hex Head Cap Screws, Cable Ties)</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>339</th>\n",
       "      <td>0.024398</td>\n",
       "      <td>(Hex Nuts, Cable Ties)</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>341</th>\n",
       "      <td>0.031103</td>\n",
       "      <td>(Jobber Length Drill Bits, Cable Ties)</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>348</th>\n",
       "      <td>0.027453</td>\n",
       "      <td>(Pipe Sealant Tape, Cable Ties)</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>353</th>\n",
       "      <td>0.028667</td>\n",
       "      <td>(Safety Glasses, Cable Ties)</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>357</th>\n",
       "      <td>0.042955</td>\n",
       "      <td>(Standard Batteries, Cable Ties)</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>372</th>\n",
       "      <td>0.025483</td>\n",
       "      <td>(Cut-Resistant Gloves, Chemical Resistant Gloves)</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>373</th>\n",
       "      <td>0.026750</td>\n",
       "      <td>(Disposable Gloves, Chemical Resistant Gloves)</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>380</th>\n",
       "      <td>0.036028</td>\n",
       "      <td>(Safety Glasses, Chemical Resistant Gloves)</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>382</th>\n",
       "      <td>0.023436</td>\n",
       "      <td>(Standard Batteries, Chemical Resistant Gloves)</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>389</th>\n",
       "      <td>0.037777</td>\n",
       "      <td>(Cut-Resistant Gloves, Coated Gloves)</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>391</th>\n",
       "      <td>0.040519</td>\n",
       "      <td>(Disposable Gloves, Coated Gloves)</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>394</th>\n",
       "      <td>0.025597</td>\n",
       "      <td>(Duct and Cloth Tapes, Coated Gloves)</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>395</th>\n",
       "      <td>0.023383</td>\n",
       "      <td>(Ear Plugs, Coated Gloves)</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>396</th>\n",
       "      <td>0.024727</td>\n",
       "      <td>(Electrical Tapes, Coated Gloves)</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>401</th>\n",
       "      <td>0.031790</td>\n",
       "      <td>(Leather Work Gloves, Coated Gloves)</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>407</th>\n",
       "      <td>0.066971</td>\n",
       "      <td>(Safety Glasses, Coated Gloves)</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>409</th>\n",
       "      <td>0.044322</td>\n",
       "      <td>(Coated Gloves, Standard Batteries)</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>415</th>\n",
       "      <td>0.020488</td>\n",
       "      <td>(Coin and Button Cell Batteries, Standard Batt...</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>419</th>\n",
       "      <td>0.022512</td>\n",
       "      <td>(Cut-Resistant Gloves, Cut-Resistant Sleeves)</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>420</th>\n",
       "      <td>0.042527</td>\n",
       "      <td>(Cut-Resistant Gloves, Disposable Gloves)</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>423</th>\n",
       "      <td>0.027789</td>\n",
       "      <td>(Cut-Resistant Gloves, Duct and Cloth Tapes)</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>424</th>\n",
       "      <td>0.027018</td>\n",
       "      <td>(Ear Plugs, Cut-Resistant Gloves)</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>425</th>\n",
       "      <td>0.031111</td>\n",
       "      <td>(Cut-Resistant Gloves, Electrical Tapes)</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>890</th>\n",
       "      <td>0.023039</td>\n",
       "      <td>(Trash Bags, Standard Batteries)</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>892</th>\n",
       "      <td>0.025284</td>\n",
       "      <td>(Utility Knife Blades, Standard Batteries)</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>898</th>\n",
       "      <td>0.028675</td>\n",
       "      <td>(Trash Bags, Toilet Paper)</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>924</th>\n",
       "      <td>0.022703</td>\n",
       "      <td>(Hex Head Cap Screws, Flat Washers, Cable Ties)</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>951</th>\n",
       "      <td>0.028491</td>\n",
       "      <td>(Safety Glasses, Cut-Resistant Gloves, Coated ...</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>956</th>\n",
       "      <td>0.025101</td>\n",
       "      <td>(Safety Glasses, Disposable Gloves, Coated Glo...</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>964</th>\n",
       "      <td>0.023291</td>\n",
       "      <td>(Safety Glasses, Leather Work Gloves, Coated G...</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>969</th>\n",
       "      <td>0.029179</td>\n",
       "      <td>(Safety Glasses, Coated Gloves, Standard Batte...</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>976</th>\n",
       "      <td>0.029118</td>\n",
       "      <td>(Safety Glasses, Cut-Resistant Gloves, Disposa...</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>982</th>\n",
       "      <td>0.020313</td>\n",
       "      <td>(Ear Plugs, Cut-Resistant Gloves, Safety Glasses)</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>985</th>\n",
       "      <td>0.022986</td>\n",
       "      <td>(Safety Glasses, Cut-Resistant Gloves, Electri...</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>988</th>\n",
       "      <td>0.029896</td>\n",
       "      <td>(Safety Glasses, Cut-Resistant Gloves, Leather...</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>997</th>\n",
       "      <td>0.020168</td>\n",
       "      <td>(Safety Glasses, Cut-Resistant Gloves, Safety ...</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>0.037350</td>\n",
       "      <td>(Safety Glasses, Cut-Resistant Gloves, Standar...</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1012</th>\n",
       "      <td>0.021061</td>\n",
       "      <td>(Safety Glasses, Ear Plugs, Disposable Gloves)</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1026</th>\n",
       "      <td>0.029820</td>\n",
       "      <td>(Safety Glasses, Disposable Gloves, Standard B...</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1041</th>\n",
       "      <td>0.024925</td>\n",
       "      <td>(Safety Glasses, Duct and Cloth Tapes, Standar...</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1046</th>\n",
       "      <td>0.021535</td>\n",
       "      <td>(Hex Head Cap Screws, Electrical Tapes, Flat W...</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1063</th>\n",
       "      <td>0.029270</td>\n",
       "      <td>(Safety Glasses, Electrical Tapes, Standard Ba...</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1065</th>\n",
       "      <td>0.043176</td>\n",
       "      <td>(Hex Head Cap Screws, Flat Washers, Hex Nuts)</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1066</th>\n",
       "      <td>0.024253</td>\n",
       "      <td>(Jobber Length Drill Bits, Hex Head Cap Screws...</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1067</th>\n",
       "      <td>0.026452</td>\n",
       "      <td>(Lock Nuts, Hex Head Cap Screws, Flat Washers)</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1068</th>\n",
       "      <td>0.037525</td>\n",
       "      <td>(Hex Head Cap Screws, Flat Washers, Lock Washers)</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1076</th>\n",
       "      <td>0.020023</td>\n",
       "      <td>(Jobber Length Drill Bits, Flat Washers, Hex N...</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1077</th>\n",
       "      <td>0.020236</td>\n",
       "      <td>(Lock Nuts, Flat Washers, Hex Nuts)</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1078</th>\n",
       "      <td>0.032714</td>\n",
       "      <td>(Flat Washers, Hex Nuts, Lock Washers)</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1098</th>\n",
       "      <td>0.029011</td>\n",
       "      <td>(Hex Head Cap Screws, Hex Nuts, Lock Washers)</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1113</th>\n",
       "      <td>0.031523</td>\n",
       "      <td>(Safety Glasses, Leather Work Gloves, Standard...</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1118</th>\n",
       "      <td>0.023024</td>\n",
       "      <td>(Trash Bags, Toilet Paper, Paper Towels, Rolls)</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1151</th>\n",
       "      <td>0.026109</td>\n",
       "      <td>(Hex Head Cap Screws, Flat Washers, Hex Nuts, ...</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>169 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       support                                           itemsets  length\n",
       "302   0.034891                  (Black Pipe Fittings, Black Pipe)       2\n",
       "315   0.021764                (Flat Washers, Black Pipe Fittings)       2\n",
       "330   0.029003                    (Disposable Gloves, Cable Ties)       2\n",
       "332   0.028087                 (Duct and Cloth Tapes, Cable Ties)       2\n",
       "334   0.053065                     (Electrical Tapes, Cable Ties)       2\n",
       "336   0.036494                         (Flat Washers, Cable Ties)       2\n",
       "338   0.030003                  (Hex Head Cap Screws, Cable Ties)       2\n",
       "339   0.024398                             (Hex Nuts, Cable Ties)       2\n",
       "341   0.031103             (Jobber Length Drill Bits, Cable Ties)       2\n",
       "348   0.027453                    (Pipe Sealant Tape, Cable Ties)       2\n",
       "353   0.028667                       (Safety Glasses, Cable Ties)       2\n",
       "357   0.042955                   (Standard Batteries, Cable Ties)       2\n",
       "372   0.025483  (Cut-Resistant Gloves, Chemical Resistant Gloves)       2\n",
       "373   0.026750     (Disposable Gloves, Chemical Resistant Gloves)       2\n",
       "380   0.036028        (Safety Glasses, Chemical Resistant Gloves)       2\n",
       "382   0.023436    (Standard Batteries, Chemical Resistant Gloves)       2\n",
       "389   0.037777              (Cut-Resistant Gloves, Coated Gloves)       2\n",
       "391   0.040519                 (Disposable Gloves, Coated Gloves)       2\n",
       "394   0.025597              (Duct and Cloth Tapes, Coated Gloves)       2\n",
       "395   0.023383                         (Ear Plugs, Coated Gloves)       2\n",
       "396   0.024727                  (Electrical Tapes, Coated Gloves)       2\n",
       "401   0.031790               (Leather Work Gloves, Coated Gloves)       2\n",
       "407   0.066971                    (Safety Glasses, Coated Gloves)       2\n",
       "409   0.044322                (Coated Gloves, Standard Batteries)       2\n",
       "415   0.020488  (Coin and Button Cell Batteries, Standard Batt...       2\n",
       "419   0.022512      (Cut-Resistant Gloves, Cut-Resistant Sleeves)       2\n",
       "420   0.042527          (Cut-Resistant Gloves, Disposable Gloves)       2\n",
       "423   0.027789       (Cut-Resistant Gloves, Duct and Cloth Tapes)       2\n",
       "424   0.027018                  (Ear Plugs, Cut-Resistant Gloves)       2\n",
       "425   0.031111           (Cut-Resistant Gloves, Electrical Tapes)       2\n",
       "...        ...                                                ...     ...\n",
       "890   0.023039                   (Trash Bags, Standard Batteries)       2\n",
       "892   0.025284         (Utility Knife Blades, Standard Batteries)       2\n",
       "898   0.028675                         (Trash Bags, Toilet Paper)       2\n",
       "924   0.022703    (Hex Head Cap Screws, Flat Washers, Cable Ties)       3\n",
       "951   0.028491  (Safety Glasses, Cut-Resistant Gloves, Coated ...       3\n",
       "956   0.025101  (Safety Glasses, Disposable Gloves, Coated Glo...       3\n",
       "964   0.023291  (Safety Glasses, Leather Work Gloves, Coated G...       3\n",
       "969   0.029179  (Safety Glasses, Coated Gloves, Standard Batte...       3\n",
       "976   0.029118  (Safety Glasses, Cut-Resistant Gloves, Disposa...       3\n",
       "982   0.020313  (Ear Plugs, Cut-Resistant Gloves, Safety Glasses)       3\n",
       "985   0.022986  (Safety Glasses, Cut-Resistant Gloves, Electri...       3\n",
       "988   0.029896  (Safety Glasses, Cut-Resistant Gloves, Leather...       3\n",
       "997   0.020168  (Safety Glasses, Cut-Resistant Gloves, Safety ...       3\n",
       "998   0.037350  (Safety Glasses, Cut-Resistant Gloves, Standar...       3\n",
       "1012  0.021061     (Safety Glasses, Ear Plugs, Disposable Gloves)       3\n",
       "1026  0.029820  (Safety Glasses, Disposable Gloves, Standard B...       3\n",
       "1041  0.024925  (Safety Glasses, Duct and Cloth Tapes, Standar...       3\n",
       "1046  0.021535  (Hex Head Cap Screws, Electrical Tapes, Flat W...       3\n",
       "1063  0.029270  (Safety Glasses, Electrical Tapes, Standard Ba...       3\n",
       "1065  0.043176      (Hex Head Cap Screws, Flat Washers, Hex Nuts)       3\n",
       "1066  0.024253  (Jobber Length Drill Bits, Hex Head Cap Screws...       3\n",
       "1067  0.026452     (Lock Nuts, Hex Head Cap Screws, Flat Washers)       3\n",
       "1068  0.037525  (Hex Head Cap Screws, Flat Washers, Lock Washers)       3\n",
       "1076  0.020023  (Jobber Length Drill Bits, Flat Washers, Hex N...       3\n",
       "1077  0.020236                (Lock Nuts, Flat Washers, Hex Nuts)       3\n",
       "1078  0.032714             (Flat Washers, Hex Nuts, Lock Washers)       3\n",
       "1098  0.029011      (Hex Head Cap Screws, Hex Nuts, Lock Washers)       3\n",
       "1113  0.031523  (Safety Glasses, Leather Work Gloves, Standard...       3\n",
       "1118  0.023024    (Trash Bags, Toilet Paper, Paper Towels, Rolls)       3\n",
       "1151  0.026109  (Hex Head Cap Screws, Flat Washers, Hex Nuts, ...       4\n",
       "\n",
       "[169 rows x 3 columns]"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Filter out single-item orders \n",
    "freq_itemsets[ (freq_itemsets['length'] > 1) &\n",
    "             (freq_itemsets['support'] > 0.02) ]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Create Recommendations\n",
    "Now we can generate a dataframe of association rules and their corresponding metrics. We will focus on the support, lift, and confidence of each association. This will ensure that the associations our recommendations will be based on occur at a relative frequency (support) that is higher than expected with random associations (lift) to some degree of confidence."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>antecedents</th>\n",
       "      <th>consequents</th>\n",
       "      <th>antecedent support</th>\n",
       "      <th>consequent support</th>\n",
       "      <th>support</th>\n",
       "      <th>confidence</th>\n",
       "      <th>lift</th>\n",
       "      <th>leverage</th>\n",
       "      <th>conviction</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>(Abrasive Cut-Off and Chop Wheels)</td>\n",
       "      <td>(Cable Ties)</td>\n",
       "      <td>0.055478</td>\n",
       "      <td>0.137088</td>\n",
       "      <td>0.012081</td>\n",
       "      <td>0.217756</td>\n",
       "      <td>1.588438</td>\n",
       "      <td>0.004475</td>\n",
       "      <td>1.103124</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>(Cable Ties)</td>\n",
       "      <td>(Abrasive Cut-Off and Chop Wheels)</td>\n",
       "      <td>0.137088</td>\n",
       "      <td>0.055478</td>\n",
       "      <td>0.012081</td>\n",
       "      <td>0.088124</td>\n",
       "      <td>1.588438</td>\n",
       "      <td>0.004475</td>\n",
       "      <td>1.035800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>(Abrasive Cut-Off and Chop Wheels)</td>\n",
       "      <td>(Depressed Center Wheels)</td>\n",
       "      <td>0.055478</td>\n",
       "      <td>0.042527</td>\n",
       "      <td>0.013287</td>\n",
       "      <td>0.239504</td>\n",
       "      <td>5.631817</td>\n",
       "      <td>0.010928</td>\n",
       "      <td>1.259012</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>(Depressed Center Wheels)</td>\n",
       "      <td>(Abrasive Cut-Off and Chop Wheels)</td>\n",
       "      <td>0.042527</td>\n",
       "      <td>0.055478</td>\n",
       "      <td>0.013287</td>\n",
       "      <td>0.312444</td>\n",
       "      <td>5.631817</td>\n",
       "      <td>0.010928</td>\n",
       "      <td>1.373738</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>(Abrasive Cut-Off and Chop Wheels)</td>\n",
       "      <td>(Duct and Cloth Tapes)</td>\n",
       "      <td>0.055478</td>\n",
       "      <td>0.171658</td>\n",
       "      <td>0.012256</td>\n",
       "      <td>0.220922</td>\n",
       "      <td>1.286988</td>\n",
       "      <td>0.002733</td>\n",
       "      <td>1.063234</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                          antecedents                         consequents  \\\n",
       "0  (Abrasive Cut-Off and Chop Wheels)                        (Cable Ties)   \n",
       "1                        (Cable Ties)  (Abrasive Cut-Off and Chop Wheels)   \n",
       "2  (Abrasive Cut-Off and Chop Wheels)           (Depressed Center Wheels)   \n",
       "3           (Depressed Center Wheels)  (Abrasive Cut-Off and Chop Wheels)   \n",
       "4  (Abrasive Cut-Off and Chop Wheels)              (Duct and Cloth Tapes)   \n",
       "\n",
       "   antecedent support  consequent support   support  confidence      lift  \\\n",
       "0            0.055478            0.137088  0.012081    0.217756  1.588438   \n",
       "1            0.137088            0.055478  0.012081    0.088124  1.588438   \n",
       "2            0.055478            0.042527  0.013287    0.239504  5.631817   \n",
       "3            0.042527            0.055478  0.013287    0.312444  5.631817   \n",
       "4            0.055478            0.171658  0.012256    0.220922  1.286988   \n",
       "\n",
       "   leverage  conviction  \n",
       "0  0.004475    1.103124  \n",
       "1  0.004475    1.035800  \n",
       "2  0.010928    1.259012  \n",
       "3  0.010928    1.373738  \n",
       "4  0.002733    1.063234  "
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Generate association rules to make recommendations using lift metric to choose items that are purchased together \n",
    "# more often than expected\n",
    "rules = association_rules(freq_itemsets, metric=\"lift\", min_threshold=1)\n",
    "rules.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Generally, a lift above 1 can infer some association. We will filter out associations that have a lift of at least 6 and confidence of at least 80% to find the most relevant recommendations."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>antecedents</th>\n",
       "      <th>consequents</th>\n",
       "      <th>antecedent support</th>\n",
       "      <th>consequent support</th>\n",
       "      <th>support</th>\n",
       "      <th>confidence</th>\n",
       "      <th>lift</th>\n",
       "      <th>leverage</th>\n",
       "      <th>conviction</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2949</th>\n",
       "      <td>(Lock Nuts, Hex Head Cap Screws, Hex Nuts, Loc...</td>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>0.012218</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.011447</td>\n",
       "      <td>0.936875</td>\n",
       "      <td>8.009248</td>\n",
       "      <td>0.010018</td>\n",
       "      <td>13.988528</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2922</th>\n",
       "      <td>(Lock Nuts, Hex Nuts, Lock Washers)</td>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>0.014219</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.013127</td>\n",
       "      <td>0.923201</td>\n",
       "      <td>7.892349</td>\n",
       "      <td>0.011464</td>\n",
       "      <td>11.497861</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2893</th>\n",
       "      <td>(Lock Nuts, Hex Head Cap Screws, Lock Washers)</td>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>0.017495</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.015899</td>\n",
       "      <td>0.908773</td>\n",
       "      <td>7.769010</td>\n",
       "      <td>0.013852</td>\n",
       "      <td>9.679484</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2840</th>\n",
       "      <td>(Hex Head Cap Screws, Hex Nuts, Lock Washers)</td>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>0.029011</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.026109</td>\n",
       "      <td>0.899974</td>\n",
       "      <td>7.693782</td>\n",
       "      <td>0.022715</td>\n",
       "      <td>8.827935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2825</th>\n",
       "      <td>(Lock Nuts, Hex Head Cap Screws, Hex Nuts)</td>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>0.018908</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.016999</td>\n",
       "      <td>0.899031</td>\n",
       "      <td>7.685721</td>\n",
       "      <td>0.014787</td>\n",
       "      <td>8.745488</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2287</th>\n",
       "      <td>(Lock Nuts, Lock Washers)</td>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>0.021336</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.018961</td>\n",
       "      <td>0.888690</td>\n",
       "      <td>7.597319</td>\n",
       "      <td>0.016465</td>\n",
       "      <td>7.933036</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2908</th>\n",
       "      <td>(Jobber Length Drill Bits, Hex Nuts, Lock Wash...</td>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>0.012676</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.011248</td>\n",
       "      <td>0.887349</td>\n",
       "      <td>7.585858</td>\n",
       "      <td>0.009766</td>\n",
       "      <td>7.838625</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2547</th>\n",
       "      <td>(Hex Nuts, Lock Washers, Cable Ties)</td>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>0.012065</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.010676</td>\n",
       "      <td>0.884810</td>\n",
       "      <td>7.564150</td>\n",
       "      <td>0.009264</td>\n",
       "      <td>7.665829</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2531</th>\n",
       "      <td>(Hex Head Cap Screws, Lock Washers, Cable Ties)</td>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>0.013913</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.012180</td>\n",
       "      <td>0.875412</td>\n",
       "      <td>7.483804</td>\n",
       "      <td>0.010553</td>\n",
       "      <td>7.087547</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2950</th>\n",
       "      <td>(Lock Nuts, Flat Washers, Hex Nuts, Lock Washers)</td>\n",
       "      <td>(Hex Head Cap Screws)</td>\n",
       "      <td>0.013127</td>\n",
       "      <td>0.100502</td>\n",
       "      <td>0.011447</td>\n",
       "      <td>0.872019</td>\n",
       "      <td>8.676589</td>\n",
       "      <td>0.010128</td>\n",
       "      <td>7.028347</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2224</th>\n",
       "      <td>(Hex Nuts, Lock Washers)</td>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>0.037579</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.032714</td>\n",
       "      <td>0.870555</td>\n",
       "      <td>7.442283</td>\n",
       "      <td>0.028319</td>\n",
       "      <td>6.821617</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2879</th>\n",
       "      <td>(Jobber Length Drill Bits, Hex Head Cap Screws...</td>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>0.014944</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.012997</td>\n",
       "      <td>0.869699</td>\n",
       "      <td>7.434963</td>\n",
       "      <td>0.011249</td>\n",
       "      <td>6.776790</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2217</th>\n",
       "      <td>(Lock Nuts, Hex Nuts)</td>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>0.023444</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.020236</td>\n",
       "      <td>0.863192</td>\n",
       "      <td>7.379341</td>\n",
       "      <td>0.017494</td>\n",
       "      <td>6.454498</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2936</th>\n",
       "      <td>(Lock Nuts, Hex Nuts, Lock Washers)</td>\n",
       "      <td>(Hex Head Cap Screws)</td>\n",
       "      <td>0.014219</td>\n",
       "      <td>0.100502</td>\n",
       "      <td>0.012218</td>\n",
       "      <td>0.859291</td>\n",
       "      <td>8.549950</td>\n",
       "      <td>0.010789</td>\n",
       "      <td>6.392612</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2300</th>\n",
       "      <td>(Self Drilling Screws, Lock Washers)</td>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>0.012149</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.010439</td>\n",
       "      <td>0.859208</td>\n",
       "      <td>7.345281</td>\n",
       "      <td>0.009018</td>\n",
       "      <td>6.271849</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2783</th>\n",
       "      <td>(Hex Head Cap Screws, Electrical Tapes, Lock W...</td>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>0.013119</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.011241</td>\n",
       "      <td>0.856810</td>\n",
       "      <td>7.324782</td>\n",
       "      <td>0.009706</td>\n",
       "      <td>6.166823</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2865</th>\n",
       "      <td>(Worm Gear Clamps, Hex Head Cap Screws, Hex Nuts)</td>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>0.013509</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.011554</td>\n",
       "      <td>0.855285</td>\n",
       "      <td>7.311747</td>\n",
       "      <td>0.009974</td>\n",
       "      <td>6.101847</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2165</th>\n",
       "      <td>(Hex Head Cap Screws, Lock Washers)</td>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>0.043970</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.037525</td>\n",
       "      <td>0.853421</td>\n",
       "      <td>7.295811</td>\n",
       "      <td>0.032382</td>\n",
       "      <td>6.024245</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2518</th>\n",
       "      <td>(Hex Head Cap Screws, Hex Nuts, Cable Ties)</td>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>0.016686</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.014127</td>\n",
       "      <td>0.846682</td>\n",
       "      <td>7.238196</td>\n",
       "      <td>0.012176</td>\n",
       "      <td>5.759437</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2811</th>\n",
       "      <td>(Jobber Length Drill Bits, Hex Head Cap Screws...</td>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>0.017770</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.015013</td>\n",
       "      <td>0.844865</td>\n",
       "      <td>7.222660</td>\n",
       "      <td>0.012935</td>\n",
       "      <td>5.691970</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2309</th>\n",
       "      <td>(Worm Gear Clamps, Lock Washers)</td>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>0.014815</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.012478</td>\n",
       "      <td>0.842268</td>\n",
       "      <td>7.200462</td>\n",
       "      <td>0.010745</td>\n",
       "      <td>5.598268</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2826</th>\n",
       "      <td>(Lock Nuts, Flat Washers, Hex Nuts)</td>\n",
       "      <td>(Hex Head Cap Screws)</td>\n",
       "      <td>0.020236</td>\n",
       "      <td>0.100502</td>\n",
       "      <td>0.016999</td>\n",
       "      <td>0.840000</td>\n",
       "      <td>8.358003</td>\n",
       "      <td>0.014965</td>\n",
       "      <td>5.621860</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2894</th>\n",
       "      <td>(Lock Nuts, Flat Washers, Lock Washers)</td>\n",
       "      <td>(Hex Head Cap Screws)</td>\n",
       "      <td>0.018961</td>\n",
       "      <td>0.100502</td>\n",
       "      <td>0.015899</td>\n",
       "      <td>0.838502</td>\n",
       "      <td>8.343096</td>\n",
       "      <td>0.013993</td>\n",
       "      <td>5.569707</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2770</th>\n",
       "      <td>(Hex Head Cap Screws, Electrical Tapes, Hex Nuts)</td>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>0.015632</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.013035</td>\n",
       "      <td>0.833903</td>\n",
       "      <td>7.128953</td>\n",
       "      <td>0.011207</td>\n",
       "      <td>5.316335</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1327</th>\n",
       "      <td>(Lock Washers, Cable Ties)</td>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>0.019748</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.016418</td>\n",
       "      <td>0.831400</td>\n",
       "      <td>7.107551</td>\n",
       "      <td>0.014108</td>\n",
       "      <td>5.237396</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2158</th>\n",
       "      <td>(Lock Nuts, Hex Head Cap Screws)</td>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>0.031874</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.026452</td>\n",
       "      <td>0.829899</td>\n",
       "      <td>7.094724</td>\n",
       "      <td>0.022724</td>\n",
       "      <td>5.191197</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2853</th>\n",
       "      <td>(Hex Head Cap Screws, Hex Nuts, Standard Batte...</td>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>0.012065</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.010011</td>\n",
       "      <td>0.829747</td>\n",
       "      <td>7.093420</td>\n",
       "      <td>0.008600</td>\n",
       "      <td>5.186546</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2147</th>\n",
       "      <td>(Hex Head Cap Screws, Hex Nuts)</td>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>0.052279</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.043176</td>\n",
       "      <td>0.825884</td>\n",
       "      <td>7.060395</td>\n",
       "      <td>0.037061</td>\n",
       "      <td>5.071472</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2740</th>\n",
       "      <td>(Trash Bags, Disposable Gloves, Toilet Paper)</td>\n",
       "      <td>(Paper Towels, Rolls)</td>\n",
       "      <td>0.012157</td>\n",
       "      <td>0.065581</td>\n",
       "      <td>0.010004</td>\n",
       "      <td>0.822864</td>\n",
       "      <td>12.547244</td>\n",
       "      <td>0.009206</td>\n",
       "      <td>5.275158</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2379</th>\n",
       "      <td>(Lock Nuts, Lock Washers)</td>\n",
       "      <td>(Hex Head Cap Screws)</td>\n",
       "      <td>0.021336</td>\n",
       "      <td>0.100502</td>\n",
       "      <td>0.017495</td>\n",
       "      <td>0.819971</td>\n",
       "      <td>8.158718</td>\n",
       "      <td>0.015351</td>\n",
       "      <td>4.996414</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1194</th>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>(Hex Head Cap Screws, Black Pipe)</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.017319</td>\n",
       "      <td>0.012669</td>\n",
       "      <td>0.108304</td>\n",
       "      <td>6.253360</td>\n",
       "      <td>0.010643</td>\n",
       "      <td>1.102035</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1212</th>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>(Hex Nuts, Black Pipe Fittings)</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.015899</td>\n",
       "      <td>0.012562</td>\n",
       "      <td>0.107390</td>\n",
       "      <td>6.754532</td>\n",
       "      <td>0.010702</td>\n",
       "      <td>1.102498</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2312</th>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>(Worm Gear Clamps, Lock Washers)</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.014815</td>\n",
       "      <td>0.012478</td>\n",
       "      <td>0.106672</td>\n",
       "      <td>7.200462</td>\n",
       "      <td>0.010745</td>\n",
       "      <td>1.102826</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1360</th>\n",
       "      <td>(Hex Head Cap Screws)</td>\n",
       "      <td>(Lock Nuts, Cable Ties)</td>\n",
       "      <td>0.100502</td>\n",
       "      <td>0.016014</td>\n",
       "      <td>0.010645</td>\n",
       "      <td>0.105919</td>\n",
       "      <td>6.614356</td>\n",
       "      <td>0.009036</td>\n",
       "      <td>1.100556</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2347</th>\n",
       "      <td>(Hex Head Cap Screws)</td>\n",
       "      <td>(Hex Nuts, Pipe Sealant Tape)</td>\n",
       "      <td>0.100502</td>\n",
       "      <td>0.015425</td>\n",
       "      <td>0.010599</td>\n",
       "      <td>0.105463</td>\n",
       "      <td>6.836933</td>\n",
       "      <td>0.009049</td>\n",
       "      <td>1.100653</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2197</th>\n",
       "      <td>(Hex Head Cap Screws)</td>\n",
       "      <td>(Flat Washers, Stainless Steel Pipe Fittings)</td>\n",
       "      <td>0.100502</td>\n",
       "      <td>0.014196</td>\n",
       "      <td>0.010569</td>\n",
       "      <td>0.105159</td>\n",
       "      <td>7.407641</td>\n",
       "      <td>0.009142</td>\n",
       "      <td>1.101653</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2186</th>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>(Quick Connect Air Couplings, Hex Head Cap Scr...</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.016472</td>\n",
       "      <td>0.012287</td>\n",
       "      <td>0.105040</td>\n",
       "      <td>6.376993</td>\n",
       "      <td>0.010360</td>\n",
       "      <td>1.098963</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2249</th>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>(Hex Nuts, Self Drilling Screws)</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.015425</td>\n",
       "      <td>0.012279</td>\n",
       "      <td>0.104975</td>\n",
       "      <td>6.805260</td>\n",
       "      <td>0.010475</td>\n",
       "      <td>1.100052</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2542</th>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>(Hex Head Cap Screws, Lock Washers, Cable Ties)</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.013913</td>\n",
       "      <td>0.012180</td>\n",
       "      <td>0.104126</td>\n",
       "      <td>7.483804</td>\n",
       "      <td>0.010553</td>\n",
       "      <td>1.100698</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2266</th>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>(Lock Nuts, Jobber Length Drill Bits)</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.015578</td>\n",
       "      <td>0.012111</td>\n",
       "      <td>0.103538</td>\n",
       "      <td>6.646348</td>\n",
       "      <td>0.010289</td>\n",
       "      <td>1.098119</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2237</th>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>(Hex Nuts, Pipe Sealant Tape)</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.015425</td>\n",
       "      <td>0.011997</td>\n",
       "      <td>0.102559</td>\n",
       "      <td>6.648672</td>\n",
       "      <td>0.010192</td>\n",
       "      <td>1.097091</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2175</th>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>(Hex Head Cap Screws, Machine Screws)</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.015166</td>\n",
       "      <td>0.011989</td>\n",
       "      <td>0.102494</td>\n",
       "      <td>6.758191</td>\n",
       "      <td>0.010215</td>\n",
       "      <td>1.097301</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2861</th>\n",
       "      <td>(Hex Head Cap Screws)</td>\n",
       "      <td>(Flat Washers, Hex Nuts, Standard Batteries)</td>\n",
       "      <td>0.100502</td>\n",
       "      <td>0.013402</td>\n",
       "      <td>0.010011</td>\n",
       "      <td>0.099612</td>\n",
       "      <td>7.432738</td>\n",
       "      <td>0.008664</td>\n",
       "      <td>1.095748</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1324</th>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>(Lock Nuts, Cable Ties)</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.016014</td>\n",
       "      <td>0.011623</td>\n",
       "      <td>0.099360</td>\n",
       "      <td>6.204779</td>\n",
       "      <td>0.009749</td>\n",
       "      <td>1.092542</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2876</th>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>(Worm Gear Clamps, Hex Head Cap Screws, Hex Nuts)</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.013509</td>\n",
       "      <td>0.011554</td>\n",
       "      <td>0.098773</td>\n",
       "      <td>7.311747</td>\n",
       "      <td>0.009974</td>\n",
       "      <td>1.094609</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2976</th>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>(Lock Nuts, Hex Head Cap Screws, Hex Nuts, Loc...</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.012218</td>\n",
       "      <td>0.011447</td>\n",
       "      <td>0.097859</td>\n",
       "      <td>8.009248</td>\n",
       "      <td>0.010018</td>\n",
       "      <td>1.094930</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2232</th>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>(Machine Screws, Hex Nuts)</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.014876</td>\n",
       "      <td>0.011325</td>\n",
       "      <td>0.096814</td>\n",
       "      <td>6.508221</td>\n",
       "      <td>0.009585</td>\n",
       "      <td>1.090722</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2917</th>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>(Jobber Length Drill Bits, Hex Nuts, Lock Wash...</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.012676</td>\n",
       "      <td>0.011248</td>\n",
       "      <td>0.096161</td>\n",
       "      <td>7.585858</td>\n",
       "      <td>0.009766</td>\n",
       "      <td>1.092367</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2794</th>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>(Hex Head Cap Screws, Electrical Tapes, Lock W...</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.013119</td>\n",
       "      <td>0.011241</td>\n",
       "      <td>0.096096</td>\n",
       "      <td>7.324782</td>\n",
       "      <td>0.009706</td>\n",
       "      <td>1.091798</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1199</th>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>(Hex Nuts, Black Pipe)</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.013646</td>\n",
       "      <td>0.010996</td>\n",
       "      <td>0.094007</td>\n",
       "      <td>6.888870</td>\n",
       "      <td>0.009400</td>\n",
       "      <td>1.088699</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2306</th>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>(Standard Batteries, Lock Washers)</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.013577</td>\n",
       "      <td>0.010882</td>\n",
       "      <td>0.093028</td>\n",
       "      <td>6.851619</td>\n",
       "      <td>0.009294</td>\n",
       "      <td>1.087600</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2554</th>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>(Hex Nuts, Lock Washers, Cable Ties)</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.012065</td>\n",
       "      <td>0.010676</td>\n",
       "      <td>0.091265</td>\n",
       "      <td>7.564150</td>\n",
       "      <td>0.009264</td>\n",
       "      <td>1.087154</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2198</th>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>(Hex Head Cap Screws, Stainless Steel Pipe Fit...</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.013700</td>\n",
       "      <td>0.010569</td>\n",
       "      <td>0.090351</td>\n",
       "      <td>6.595135</td>\n",
       "      <td>0.008966</td>\n",
       "      <td>1.084265</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1217</th>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>(Black Pipe Fittings, Lock Washers)</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.013196</td>\n",
       "      <td>0.010546</td>\n",
       "      <td>0.090155</td>\n",
       "      <td>6.832191</td>\n",
       "      <td>0.009002</td>\n",
       "      <td>1.084586</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2301</th>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>(Self Drilling Screws, Lock Washers)</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.012149</td>\n",
       "      <td>0.010439</td>\n",
       "      <td>0.089241</td>\n",
       "      <td>7.345281</td>\n",
       "      <td>0.009018</td>\n",
       "      <td>1.084646</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2055</th>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>(Lock Nuts, Electrical Tapes)</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.013661</td>\n",
       "      <td>0.010370</td>\n",
       "      <td>0.088654</td>\n",
       "      <td>6.489325</td>\n",
       "      <td>0.008772</td>\n",
       "      <td>1.082287</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1585</th>\n",
       "      <td>(Cut-Resistant Gloves)</td>\n",
       "      <td>(Standard Batteries, Cut-Resistant Sleeves)</td>\n",
       "      <td>0.124389</td>\n",
       "      <td>0.014005</td>\n",
       "      <td>0.010767</td>\n",
       "      <td>0.086561</td>\n",
       "      <td>6.180698</td>\n",
       "      <td>0.009025</td>\n",
       "      <td>1.079432</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2244</th>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>(Quick Connect Air Couplings, Hex Nuts)</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.012669</td>\n",
       "      <td>0.010095</td>\n",
       "      <td>0.086304</td>\n",
       "      <td>6.812322</td>\n",
       "      <td>0.008613</td>\n",
       "      <td>1.080590</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2295</th>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>(Pipe Sealant Tape, Lock Washers)</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.012340</td>\n",
       "      <td>0.010042</td>\n",
       "      <td>0.085847</td>\n",
       "      <td>6.956559</td>\n",
       "      <td>0.008598</td>\n",
       "      <td>1.080409</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2862</th>\n",
       "      <td>(Flat Washers)</td>\n",
       "      <td>(Hex Head Cap Screws, Hex Nuts, Standard Batte...</td>\n",
       "      <td>0.116974</td>\n",
       "      <td>0.012065</td>\n",
       "      <td>0.010011</td>\n",
       "      <td>0.085586</td>\n",
       "      <td>7.093420</td>\n",
       "      <td>0.008600</td>\n",
       "      <td>1.080401</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>612 rows × 9 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                            antecedents  \\\n",
       "2949  (Lock Nuts, Hex Head Cap Screws, Hex Nuts, Loc...   \n",
       "2922                (Lock Nuts, Hex Nuts, Lock Washers)   \n",
       "2893     (Lock Nuts, Hex Head Cap Screws, Lock Washers)   \n",
       "2840      (Hex Head Cap Screws, Hex Nuts, Lock Washers)   \n",
       "2825         (Lock Nuts, Hex Head Cap Screws, Hex Nuts)   \n",
       "2287                          (Lock Nuts, Lock Washers)   \n",
       "2908  (Jobber Length Drill Bits, Hex Nuts, Lock Wash...   \n",
       "2547               (Hex Nuts, Lock Washers, Cable Ties)   \n",
       "2531    (Hex Head Cap Screws, Lock Washers, Cable Ties)   \n",
       "2950  (Lock Nuts, Flat Washers, Hex Nuts, Lock Washers)   \n",
       "2224                           (Hex Nuts, Lock Washers)   \n",
       "2879  (Jobber Length Drill Bits, Hex Head Cap Screws...   \n",
       "2217                              (Lock Nuts, Hex Nuts)   \n",
       "2936                (Lock Nuts, Hex Nuts, Lock Washers)   \n",
       "2300               (Self Drilling Screws, Lock Washers)   \n",
       "2783  (Hex Head Cap Screws, Electrical Tapes, Lock W...   \n",
       "2865  (Worm Gear Clamps, Hex Head Cap Screws, Hex Nuts)   \n",
       "2165                (Hex Head Cap Screws, Lock Washers)   \n",
       "2518        (Hex Head Cap Screws, Hex Nuts, Cable Ties)   \n",
       "2811  (Jobber Length Drill Bits, Hex Head Cap Screws...   \n",
       "2309                   (Worm Gear Clamps, Lock Washers)   \n",
       "2826                (Lock Nuts, Flat Washers, Hex Nuts)   \n",
       "2894            (Lock Nuts, Flat Washers, Lock Washers)   \n",
       "2770  (Hex Head Cap Screws, Electrical Tapes, Hex Nuts)   \n",
       "1327                         (Lock Washers, Cable Ties)   \n",
       "2158                   (Lock Nuts, Hex Head Cap Screws)   \n",
       "2853  (Hex Head Cap Screws, Hex Nuts, Standard Batte...   \n",
       "2147                    (Hex Head Cap Screws, Hex Nuts)   \n",
       "2740      (Trash Bags, Disposable Gloves, Toilet Paper)   \n",
       "2379                          (Lock Nuts, Lock Washers)   \n",
       "...                                                 ...   \n",
       "1194                                     (Flat Washers)   \n",
       "1212                                     (Flat Washers)   \n",
       "2312                                     (Flat Washers)   \n",
       "1360                              (Hex Head Cap Screws)   \n",
       "2347                              (Hex Head Cap Screws)   \n",
       "2197                              (Hex Head Cap Screws)   \n",
       "2186                                     (Flat Washers)   \n",
       "2249                                     (Flat Washers)   \n",
       "2542                                     (Flat Washers)   \n",
       "2266                                     (Flat Washers)   \n",
       "2237                                     (Flat Washers)   \n",
       "2175                                     (Flat Washers)   \n",
       "2861                              (Hex Head Cap Screws)   \n",
       "1324                                     (Flat Washers)   \n",
       "2876                                     (Flat Washers)   \n",
       "2976                                     (Flat Washers)   \n",
       "2232                                     (Flat Washers)   \n",
       "2917                                     (Flat Washers)   \n",
       "2794                                     (Flat Washers)   \n",
       "1199                                     (Flat Washers)   \n",
       "2306                                     (Flat Washers)   \n",
       "2554                                     (Flat Washers)   \n",
       "2198                                     (Flat Washers)   \n",
       "1217                                     (Flat Washers)   \n",
       "2301                                     (Flat Washers)   \n",
       "2055                                     (Flat Washers)   \n",
       "1585                             (Cut-Resistant Gloves)   \n",
       "2244                                     (Flat Washers)   \n",
       "2295                                     (Flat Washers)   \n",
       "2862                                     (Flat Washers)   \n",
       "\n",
       "                                            consequents  antecedent support  \\\n",
       "2949                                     (Flat Washers)            0.012218   \n",
       "2922                                     (Flat Washers)            0.014219   \n",
       "2893                                     (Flat Washers)            0.017495   \n",
       "2840                                     (Flat Washers)            0.029011   \n",
       "2825                                     (Flat Washers)            0.018908   \n",
       "2287                                     (Flat Washers)            0.021336   \n",
       "2908                                     (Flat Washers)            0.012676   \n",
       "2547                                     (Flat Washers)            0.012065   \n",
       "2531                                     (Flat Washers)            0.013913   \n",
       "2950                              (Hex Head Cap Screws)            0.013127   \n",
       "2224                                     (Flat Washers)            0.037579   \n",
       "2879                                     (Flat Washers)            0.014944   \n",
       "2217                                     (Flat Washers)            0.023444   \n",
       "2936                              (Hex Head Cap Screws)            0.014219   \n",
       "2300                                     (Flat Washers)            0.012149   \n",
       "2783                                     (Flat Washers)            0.013119   \n",
       "2865                                     (Flat Washers)            0.013509   \n",
       "2165                                     (Flat Washers)            0.043970   \n",
       "2518                                     (Flat Washers)            0.016686   \n",
       "2811                                     (Flat Washers)            0.017770   \n",
       "2309                                     (Flat Washers)            0.014815   \n",
       "2826                              (Hex Head Cap Screws)            0.020236   \n",
       "2894                              (Hex Head Cap Screws)            0.018961   \n",
       "2770                                     (Flat Washers)            0.015632   \n",
       "1327                                     (Flat Washers)            0.019748   \n",
       "2158                                     (Flat Washers)            0.031874   \n",
       "2853                                     (Flat Washers)            0.012065   \n",
       "2147                                     (Flat Washers)            0.052279   \n",
       "2740                              (Paper Towels, Rolls)            0.012157   \n",
       "2379                              (Hex Head Cap Screws)            0.021336   \n",
       "...                                                 ...                 ...   \n",
       "1194                  (Hex Head Cap Screws, Black Pipe)            0.116974   \n",
       "1212                    (Hex Nuts, Black Pipe Fittings)            0.116974   \n",
       "2312                   (Worm Gear Clamps, Lock Washers)            0.116974   \n",
       "1360                            (Lock Nuts, Cable Ties)            0.100502   \n",
       "2347                      (Hex Nuts, Pipe Sealant Tape)            0.100502   \n",
       "2197      (Flat Washers, Stainless Steel Pipe Fittings)            0.100502   \n",
       "2186  (Quick Connect Air Couplings, Hex Head Cap Scr...            0.116974   \n",
       "2249                   (Hex Nuts, Self Drilling Screws)            0.116974   \n",
       "2542    (Hex Head Cap Screws, Lock Washers, Cable Ties)            0.116974   \n",
       "2266              (Lock Nuts, Jobber Length Drill Bits)            0.116974   \n",
       "2237                      (Hex Nuts, Pipe Sealant Tape)            0.116974   \n",
       "2175              (Hex Head Cap Screws, Machine Screws)            0.116974   \n",
       "2861       (Flat Washers, Hex Nuts, Standard Batteries)            0.100502   \n",
       "1324                            (Lock Nuts, Cable Ties)            0.116974   \n",
       "2876  (Worm Gear Clamps, Hex Head Cap Screws, Hex Nuts)            0.116974   \n",
       "2976  (Lock Nuts, Hex Head Cap Screws, Hex Nuts, Loc...            0.116974   \n",
       "2232                         (Machine Screws, Hex Nuts)            0.116974   \n",
       "2917  (Jobber Length Drill Bits, Hex Nuts, Lock Wash...            0.116974   \n",
       "2794  (Hex Head Cap Screws, Electrical Tapes, Lock W...            0.116974   \n",
       "1199                             (Hex Nuts, Black Pipe)            0.116974   \n",
       "2306                 (Standard Batteries, Lock Washers)            0.116974   \n",
       "2554               (Hex Nuts, Lock Washers, Cable Ties)            0.116974   \n",
       "2198  (Hex Head Cap Screws, Stainless Steel Pipe Fit...            0.116974   \n",
       "1217                (Black Pipe Fittings, Lock Washers)            0.116974   \n",
       "2301               (Self Drilling Screws, Lock Washers)            0.116974   \n",
       "2055                      (Lock Nuts, Electrical Tapes)            0.116974   \n",
       "1585        (Standard Batteries, Cut-Resistant Sleeves)            0.124389   \n",
       "2244            (Quick Connect Air Couplings, Hex Nuts)            0.116974   \n",
       "2295                  (Pipe Sealant Tape, Lock Washers)            0.116974   \n",
       "2862  (Hex Head Cap Screws, Hex Nuts, Standard Batte...            0.116974   \n",
       "\n",
       "      consequent support   support  confidence       lift  leverage  \\\n",
       "2949            0.116974  0.011447    0.936875   8.009248  0.010018   \n",
       "2922            0.116974  0.013127    0.923201   7.892349  0.011464   \n",
       "2893            0.116974  0.015899    0.908773   7.769010  0.013852   \n",
       "2840            0.116974  0.026109    0.899974   7.693782  0.022715   \n",
       "2825            0.116974  0.016999    0.899031   7.685721  0.014787   \n",
       "2287            0.116974  0.018961    0.888690   7.597319  0.016465   \n",
       "2908            0.116974  0.011248    0.887349   7.585858  0.009766   \n",
       "2547            0.116974  0.010676    0.884810   7.564150  0.009264   \n",
       "2531            0.116974  0.012180    0.875412   7.483804  0.010553   \n",
       "2950            0.100502  0.011447    0.872019   8.676589  0.010128   \n",
       "2224            0.116974  0.032714    0.870555   7.442283  0.028319   \n",
       "2879            0.116974  0.012997    0.869699   7.434963  0.011249   \n",
       "2217            0.116974  0.020236    0.863192   7.379341  0.017494   \n",
       "2936            0.100502  0.012218    0.859291   8.549950  0.010789   \n",
       "2300            0.116974  0.010439    0.859208   7.345281  0.009018   \n",
       "2783            0.116974  0.011241    0.856810   7.324782  0.009706   \n",
       "2865            0.116974  0.011554    0.855285   7.311747  0.009974   \n",
       "2165            0.116974  0.037525    0.853421   7.295811  0.032382   \n",
       "2518            0.116974  0.014127    0.846682   7.238196  0.012176   \n",
       "2811            0.116974  0.015013    0.844865   7.222660  0.012935   \n",
       "2309            0.116974  0.012478    0.842268   7.200462  0.010745   \n",
       "2826            0.100502  0.016999    0.840000   8.358003  0.014965   \n",
       "2894            0.100502  0.015899    0.838502   8.343096  0.013993   \n",
       "2770            0.116974  0.013035    0.833903   7.128953  0.011207   \n",
       "1327            0.116974  0.016418    0.831400   7.107551  0.014108   \n",
       "2158            0.116974  0.026452    0.829899   7.094724  0.022724   \n",
       "2853            0.116974  0.010011    0.829747   7.093420  0.008600   \n",
       "2147            0.116974  0.043176    0.825884   7.060395  0.037061   \n",
       "2740            0.065581  0.010004    0.822864  12.547244  0.009206   \n",
       "2379            0.100502  0.017495    0.819971   8.158718  0.015351   \n",
       "...                  ...       ...         ...        ...       ...   \n",
       "1194            0.017319  0.012669    0.108304   6.253360  0.010643   \n",
       "1212            0.015899  0.012562    0.107390   6.754532  0.010702   \n",
       "2312            0.014815  0.012478    0.106672   7.200462  0.010745   \n",
       "1360            0.016014  0.010645    0.105919   6.614356  0.009036   \n",
       "2347            0.015425  0.010599    0.105463   6.836933  0.009049   \n",
       "2197            0.014196  0.010569    0.105159   7.407641  0.009142   \n",
       "2186            0.016472  0.012287    0.105040   6.376993  0.010360   \n",
       "2249            0.015425  0.012279    0.104975   6.805260  0.010475   \n",
       "2542            0.013913  0.012180    0.104126   7.483804  0.010553   \n",
       "2266            0.015578  0.012111    0.103538   6.646348  0.010289   \n",
       "2237            0.015425  0.011997    0.102559   6.648672  0.010192   \n",
       "2175            0.015166  0.011989    0.102494   6.758191  0.010215   \n",
       "2861            0.013402  0.010011    0.099612   7.432738  0.008664   \n",
       "1324            0.016014  0.011623    0.099360   6.204779  0.009749   \n",
       "2876            0.013509  0.011554    0.098773   7.311747  0.009974   \n",
       "2976            0.012218  0.011447    0.097859   8.009248  0.010018   \n",
       "2232            0.014876  0.011325    0.096814   6.508221  0.009585   \n",
       "2917            0.012676  0.011248    0.096161   7.585858  0.009766   \n",
       "2794            0.013119  0.011241    0.096096   7.324782  0.009706   \n",
       "1199            0.013646  0.010996    0.094007   6.888870  0.009400   \n",
       "2306            0.013577  0.010882    0.093028   6.851619  0.009294   \n",
       "2554            0.012065  0.010676    0.091265   7.564150  0.009264   \n",
       "2198            0.013700  0.010569    0.090351   6.595135  0.008966   \n",
       "1217            0.013196  0.010546    0.090155   6.832191  0.009002   \n",
       "2301            0.012149  0.010439    0.089241   7.345281  0.009018   \n",
       "2055            0.013661  0.010370    0.088654   6.489325  0.008772   \n",
       "1585            0.014005  0.010767    0.086561   6.180698  0.009025   \n",
       "2244            0.012669  0.010095    0.086304   6.812322  0.008613   \n",
       "2295            0.012340  0.010042    0.085847   6.956559  0.008598   \n",
       "2862            0.012065  0.010011    0.085586   7.093420  0.008600   \n",
       "\n",
       "      conviction  \n",
       "2949   13.988528  \n",
       "2922   11.497861  \n",
       "2893    9.679484  \n",
       "2840    8.827935  \n",
       "2825    8.745488  \n",
       "2287    7.933036  \n",
       "2908    7.838625  \n",
       "2547    7.665829  \n",
       "2531    7.087547  \n",
       "2950    7.028347  \n",
       "2224    6.821617  \n",
       "2879    6.776790  \n",
       "2217    6.454498  \n",
       "2936    6.392612  \n",
       "2300    6.271849  \n",
       "2783    6.166823  \n",
       "2865    6.101847  \n",
       "2165    6.024245  \n",
       "2518    5.759437  \n",
       "2811    5.691970  \n",
       "2309    5.598268  \n",
       "2826    5.621860  \n",
       "2894    5.569707  \n",
       "2770    5.316335  \n",
       "1327    5.237396  \n",
       "2158    5.191197  \n",
       "2853    5.186546  \n",
       "2147    5.071472  \n",
       "2740    5.275158  \n",
       "2379    4.996414  \n",
       "...          ...  \n",
       "1194    1.102035  \n",
       "1212    1.102498  \n",
       "2312    1.102826  \n",
       "1360    1.100556  \n",
       "2347    1.100653  \n",
       "2197    1.101653  \n",
       "2186    1.098963  \n",
       "2249    1.100052  \n",
       "2542    1.100698  \n",
       "2266    1.098119  \n",
       "2237    1.097091  \n",
       "2175    1.097301  \n",
       "2861    1.095748  \n",
       "1324    1.092542  \n",
       "2876    1.094609  \n",
       "2976    1.094930  \n",
       "2232    1.090722  \n",
       "2917    1.092367  \n",
       "2794    1.091798  \n",
       "1199    1.088699  \n",
       "2306    1.087600  \n",
       "2554    1.087154  \n",
       "2198    1.084265  \n",
       "1217    1.084586  \n",
       "2301    1.084646  \n",
       "2055    1.082287  \n",
       "1585    1.079432  \n",
       "2244    1.080590  \n",
       "2295    1.080409  \n",
       "2862    1.080401  \n",
       "\n",
       "[612 rows x 9 columns]"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Filter items and save\n",
    "saved_recs = rules[ (rules['lift'] >= 6) &\n",
    "     rules['confidence'] >= 0.8]\n",
    "\n",
    "# Check saved dataframe\n",
    "saved_recs.sort_values(by=['confidence'], ascending=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The final step now that recommendations have been generated is to save them as a csv file for later use."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Save Recs to csv\n",
    "saved_recs.to_csv('recommendations.csv', index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##  Summary\n",
    "\n",
    "The apriori algorithm and association rule mining were used to extract frequent itemsets (items purchased together) from the data and generate rules for frequent item patterns. These rules can be used in a recommendation engine in the context of \"customers who viewed ... also viewed...\" and \"customers who purchased ... also purchased...\" in order to encourage add-on purchases or encourage past customers to  continue using \"The Company\" for their e-commerce needs. The results are contained in a CSV file that can be used across platforms for production purposes."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
